package org.edu.modules.terminal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Map;
import org.edu.common.config.pojo.POJOUtils;
import org.edu.modules.course.entity.VeCuzCourse;
import org.edu.modules.course.mapper.VeCuzCourseMapper;
import org.edu.modules.course.service.IVeCuzCourseService;
import org.edu.modules.liancategory.entity.VeCuzCourseCategory;
import org.edu.modules.liancategory.service.IVeCuzCourseCategoryService;
import org.edu.modules.maker.entity.VeCuzCourseMaker;
import org.edu.modules.maker.service.IVeCuzCourseMakerService;
import org.edu.modules.summary.entity.VeCuzCourseSummary;
import org.edu.modules.summary.service.IVeCuzCourseSummaryService;
import org.edu.modules.terminal.entity.VeCuzTerminal;
import org.edu.modules.terminal.entity.VeCuzTerminalBo;
import org.edu.modules.terminal.entity.VeCuzTerminalCourse;
import org.edu.modules.terminal.mapper.VeCuzTerminalMapper;
import org.edu.modules.terminal.service.IVeCuzTerminalService;
import org.edu.page.PageCondition;
import org.edu.page.PageResult;
import org.edu.page.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VeCuzTerminalServiceImpl
        extends ServiceImpl<VeCuzTerminalMapper, VeCuzTerminal>
        implements IVeCuzTerminalService
{
    @Autowired
    IVeCuzCourseService veCuzCourseService;
    @Autowired
    IVeCuzCourseCategoryService veCuzCourseCategoryService;
    @Autowired
    IVeCuzTerminalService veCuzTerminalService;
    @Autowired
    IVeCuzCourseMakerService veCuzCourseMakerService;
    @Autowired
    IVeCuzCourseSummaryService veCuzCourseSummaryService;
    @Autowired
    VeCuzCourseMapper veCuzCourseMapper;
    @Autowired
    VeCuzTerminalMapper veCuzTerminalMapper;

    public PageResult findAllPage(PageCondition pageInitCondition)
    {
        PageHelper.startPage(pageInitCondition.getPageIndex(), pageInitCondition.getPageSize());
        List<VeCuzTerminal> veCuzTerminals = this.veCuzTerminalMapper.findAllByPage(pageInitCondition.getFilter());
        List<VeCuzTerminalBo> zyEquInfoBOS = POJOUtils.listCopyProperties(veCuzTerminals, VeCuzTerminalBo.class);




        PageInfo pageInfo = new PageInfo(zyEquInfoBOS);

        PageResult pageReslt = PageUtils.getPageReslt(pageInfo, zyEquInfoBOS);
        return pageReslt;
    }

    public List<VeCuzTerminal> findAllByPages(PageCondition pageInitCondition)
    {
        List<VeCuzTerminal> veCuzTerminals = this.veCuzTerminalMapper.findAllByPage(pageInitCondition.getFilter());
        return veCuzTerminals;
    }

    public IPage<Map<String, Object>> train(Page<Map<String, Object>> page, QueryWrapper<VeCuzTerminal> queryWrapper)
    {
        return ((VeCuzTerminalMapper)getBaseMapper()).train(page, queryWrapper);
    }

    public IPage<Map<String, Object>> xmsiteLageMaps(Page<Map<String, Object>> page, QueryWrapper<VeCuzTerminal> queryWrapper)
    {
        return ((VeCuzTerminalMapper)getBaseMapper()).xmsitePageMaps(page, queryWrapper);
    }

    public boolean saveTerminal(VeCuzCourse veCuzCourse, VeCuzCourseCategory veCuzCourseCategory, List<VeCuzCourseMaker> veCuzCourseMakerList, VeCuzCourseSummary veCuzCourseSummary, VeCuzTerminal veCuzTerminal)
    {
        int cuz = this.veCuzCourseMapper.insert(veCuzCourse);
        if (cuz < 1) {
            return false;
        }
        int courseid = 0;
        courseid = veCuzCourse.getId().intValue();
        veCuzCourseCategory.setCourseid(Integer.valueOf(courseid));

        veCuzCourseSummary.setCourseid(Integer.valueOf(courseid));
        veCuzTerminal.setCourseid(Integer.valueOf(courseid));
        boolean retCata = this.veCuzCourseCategoryService.saveCate(veCuzCourseCategory);
        if (!retCata) {
            return false;
        }
        for (int i = 0; i < veCuzCourseMakerList.size(); i++)
        {
            VeCuzCourseMaker veCuzCourseMaker = (VeCuzCourseMaker)veCuzCourseMakerList.get(i);
            veCuzCourseMaker.setCourseid(Integer.valueOf(courseid));
        }
        boolean retMaker = this.veCuzCourseMakerService.saveBatch(veCuzCourseMakerList);



        boolean retSummy = this.veCuzCourseSummaryService.saveSummary(veCuzCourseSummary);
        if (!retSummy) {
            return false;
        }
        boolean retTeminal = this.veCuzTerminalService.saveTer(veCuzTerminal);
        if (!retTeminal) {
            return false;
        }
        return false;
    }

    public boolean saveTer(VeCuzTerminal veCuzTerminal)
    {
        return SqlHelper.retBool(Integer.valueOf(((VeCuzTerminalMapper)getBaseMapper()).insert(veCuzTerminal)));
    }

    public IPage<Map<String, Object>> makeLageMaps(Page<Map<String, Object>> page, QueryWrapper<VeCuzTerminalCourse> queryWrapper)
    {
        return ((VeCuzTerminalMapper)getBaseMapper()).makePageMaps(page, queryWrapper);
    }

    public IPage<Map<String, Object>> makeedLageMaps(Page<Map<String, Object>> page, QueryWrapper<VeCuzTerminalCourse> queryWrapper)
    {
        return ((VeCuzTerminalMapper)getBaseMapper()).makeedPageMaps(page, queryWrapper);
    }
}
